<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        /* 
            字符串常用函数
         */
        let str1 = "aabbcc";
        console.log(str1.at(41));//undefined
        console.log(str1.charAt(41));//返回的是 ''
        /* 
            at方法比charAt方法更加严谨，表现在给的参数来到数组的越界位置时，at会返回undefined
            而charAt返回的是''
        */
        console.log("===============================");

        let str2 = "abcdef";
        console.log(str2.endsWith("def"));
        console.log(str2.endsWith("bc",3));//不包含3下标
        console.log("===============================");

        let str3 = "aaBbcbc"
        const strIndex = str3.indexOf('b');
        console.log(strIndex);
        console.log(str3.lastIndexOf('b'));

        console.log(str3.indexOf('a',5));   //找不到对应的元素返回 -1 包含指定位置
        console.log(str3.indexOf('a',-12)); //不支持负数
        console.log("===============================");

        let str4 = "aaaabbbbcccccccccccccceeddddffff";
        //需求：统计c出现了多少次
        let count = 0;
        let position = str4.indexOf("c");
        console.log(position);
        while(position !== -1){
            count++;
            position = str4.indexOf("c",position + 1);
        }
        console.log(count);
    </script>
</head>
<body>
    
</body>
</html>